package com.waimai.entity;

import java.util.ArrayList;

import com.waimai.constant.URLConstant;
import com.waimai.log.Log;

/**
 * 餐厅实体
 * 
 * @author comingundone
 * 
 * @param id
 *            是company+href
 * 
 * @param mName
 *            餐厅名称
 * @param mSaleList
 *            满减列表
 * @param mHrefUrl
 *            餐厅链接Url
 * @param mDrinkList
 *            饮料列表
 * @param mCompany
 *            公司
 * @param mMaxBack
 *            最高红包
 * @param mStatus
 *            餐厅状态
 * @param mMinusRatio
 *            减满比
 * @param mImgUrl
 *            餐厅图标Url
 * @param mTotalPerMon
 *            月售份数
 * 
 * 
 */
public class Restaurant {

	protected String mId;
	protected String mName;
	protected ArrayList<Sale> mSaleList;
	protected String mHrefUrl;
	protected ArrayList<String> mDrinkList;
	protected int mCompany;
	protected int mMaxBack;
	protected int mStatus;
	protected double mMinusRatio;
	protected String mImgUrl;
	protected String mTotalPerMon;

	public Restaurant() {

	}

	public Restaurant(String id, String name, ArrayList<Sale> saleList,
			String hrefUrl, ArrayList<String> drinkList, int company,
			int maxBack, int status, String imgUrl, String totalPerMon) {
		super();
		this.mId = id;
		this.mName = name;
		this.mSaleList = saleList;
		this.mHrefUrl = hrefUrl;
		this.mDrinkList = drinkList;
		this.mCompany = company;
		this.mMaxBack = maxBack;
		this.mStatus = status;
		setMinusRatio();
		this.mImgUrl = imgUrl;
		this.mTotalPerMon = totalPerMon;
	}

	public Restaurant(String name, ArrayList<Sale> saleList, String hrefUrl,
			ArrayList<String> drinkList, int company, int maxBack, int status,
			String imgUrl, String totalPerMon) {
		super();
		this.mName = name;
		this.mSaleList = saleList;
		this.mHrefUrl = hrefUrl;
		this.mDrinkList = drinkList;
		this.mCompany = company;
		this.mMaxBack = maxBack;
		this.mStatus = status;
		setMinusRatio();
		this.mImgUrl = imgUrl;
		this.mTotalPerMon = totalPerMon;
	}

	public String getId() {
		return mId;
	}

	protected void setMinusRatio() {
		mMinusRatio = (mSaleList == null || mSaleList.size() == 0) ? 1
				: mSaleList.size() == 0 ? 1 : (double) mSaleList.get(0)
						.getMinus() / (double) mSaleList.get(0).getFull();
	}

	public double getMinusRatio() {
		return mMinusRatio;
	}

	public void setName(String mName) {
		this.mName = mName;
	}

	public String getSaleString() {
		StringBuilder sb = new StringBuilder();
		if (mSaleList != null) {
			for (int i = 0; i < mSaleList.size(); i++) {
				if (i > 0) {
					sb.append(";");
				}
				sb.append("满" + mSaleList.get(i).getFull() + "减"
						+ mSaleList.get(i).getMinus());
			}
		} else {
			Log.e("restaurantSaleList is null");
		}
		return sb.toString();
	}

	public ArrayList<Sale> getSaleList() {
		return mSaleList;
	}

	public void setSaleList(ArrayList<Sale> mSaleList) {
		this.mSaleList = mSaleList;
		setMinusRatio();
	}

	public ArrayList<String> getDrinkList() {
		return mDrinkList;
	}

	public String getDrinkString() {
		StringBuilder sb = new StringBuilder();
		if (mDrinkList != null) {
			for (int i = 0; i < mDrinkList.size(); i++) {
				if (i > 0) {
					sb.append(";");
				}
				sb.append(mDrinkList.get(i));
			}
		} else {
			Log.e("restaurantDrinkList is null");
		}
		return sb.toString();
	}

	public void setDrinkList(ArrayList<String> drinkList) {
		this.mDrinkList = drinkList;
	}

	public int getCompany() {
		return mCompany;
	}

	public void setCompany(int mCompany) {
		this.mCompany = mCompany;
	}

	public int getMaxBack() {
		return mMaxBack;
	}

	public void setMaxBack(int mMaxBack) {
		this.mMaxBack = mMaxBack;
	}

	public int getStatus() {
		return mStatus;
	}

	public void setStatus(int status) {
		this.mStatus = status;
	}

	public void addSale(int man, int jian) {
		mSaleList.add(new Sale(man, jian));
	}

	public String getName() {
		return mName;
	}

	public String getHrefUrl() {
		return mHrefUrl;
	}

	public void setHrefUrl(String hrefUrl) {
		this.mHrefUrl = hrefUrl;
	}

	public String getImgUrl() {
		return mImgUrl;
	}

	public void setmImgUrl(String imgUrl) {
		this.mImgUrl = imgUrl;
	}

	public String getTotalPerMon() {
		return mTotalPerMon;
	}

	public void setTotalPerMon(String totalPerMon) {
		this.mTotalPerMon = totalPerMon;
	}

	/**
	 * 
	 * @return 返回整体餐厅链接URL
	 */
	public String getWebUrl() {
		return URLConstant.URL_MEITUAN + mHrefUrl;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		sb.append("名称" + getName() + "\n");
		sb.append("链接" + getWebUrl() + "\n");
		sb.append("减钱" + getSaleString() + "\n");
		sb.append("mDrinkList" + getDrinkString() + "\n");
		sb.append("Company" + getCompany() + "\n");
		sb.append("MaxBack" + getMaxBack() + "\n");
		sb.append("Status" + getStatus() + "\n");
		sb.append("MinusRatio" + getMinusRatio() + "\n");
		sb.append("ImgUrl" + getImgUrl() + "\n");
		sb.append("TotalPerMon" + getTotalPerMon() + "\n");

		return sb.toString();
	}

}
